package com.bishe.demo.modules.account.controller;

import com.bishe.demo.modules.account.service.UserService;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class AccountController {
    @Autowired
    private UserService userService;
    @RequiresRoles({"管理员"})
    @GetMapping("/account/users")
    public String users() {
        return "index";
    }

    @RequiresRoles({"管理员"})
    @GetMapping("/account/roles")
    public String roles() {
        return "index";
    }

    @RequiresRoles({"管理员"})
    @GetMapping("/account/resources")
    public String resources() {
        return "index";
    }

    @GetMapping("/login")
    public String login(ModelMap modelMap) {
        modelMap.put("template", "/account/login");
        return "indexSimple";
    }

    @GetMapping("/register")
    public String register(ModelMap modelMap) {
        modelMap.put("template", "/account/register");
        return "indexSimple";
    }

    @GetMapping("/account/profile")
    public String profile() {
        return "index";
    }

    @GetMapping("/logout")
    public String logout() {
        userService.logout();
        return "redirect:/login";
    }
}
